<h2><%= @product.name.blank? ? "新規銘柄" : @product.name %>の編集</h2>
<%= form_for(@product, :url => {:action => :update}) do |f| %><br />
  <%= f.hidden_field :id, { :value => @product.id } %>
  <%= f.radio_button :is_show, 1, :checked => (@product.is_show == true) %>表示
  <%= f.radio_button :is_show, 0, :checked => (@product.is_show == false) %>非表示<br />
	<br />
  蔵元<%= f.select(:maker, Maker.order(:name_yomi).all.collect { |i| [i.name, i.id] }) %><br />
	<br />
  銘柄<%= f.text_field :name %><br />
  <br />
  読み<%= f.text_field :name_yomi %><br />
  <br />
  値段<br />
  <%= f.text_field :price %><br />
  ネーミングの由来<br />
  <%= f.text_area :naming, :cols => 35, :rows => 7 %><br />
  <br />
  醸造方法<%= f.select(:brew, MasterBrew.order(:sort).all.collect { |i| [i.name, i.id] }) %><br />
  <br />
  色<%= f.select(:color, MasterColor.order(:sort).all.collect { |i| [i.name, i.id] }) %><br />
  <br />
  PR<br />
  <%= f.text_area :pr, {:class => "ckeditor"} %><br />
  <br />
  記事<br />
	<%= f.text_area :article, {:class => "ckeditor"} %><br />
	<!-- 画像プレビュー -->
	<script type="text/javascript">
		$(function(){
		  $("#image_maker").change(function(){
		    ajax_post();
		  });
		  $("#image_production").change(function(){
		    ajax_post();
		  });
		  $("#image_type").change(function(){
		    ajax_post();
		  });
		});
		
		function ajax_post(){
		  var maker_val = $("#image_maker").val();
		  var prod_val = $("#image_production").val();
		  var type_val = $("#image_type").val();
		  $.ajax({
		    url: "/images/get_variable_images",
		    type: 'GET',
		    dataType: 'text',
		    data: {maker:maker_val, production:prod_val, image_type:type_val},
		    success: function(data){
		      if(data.length>0){
		        $("#images").html(data);
		      } else {
		        $("#images").html("no images");
		      }
		    },
		    error: function(){
		      alert("通信に失敗しました");
		    }
		  })
		}
		
	</script>
	<table border="1">
	<tr><td>画像アドレスのコピー</td></tr>
	<tr><td>
		<%= form_tag do %>
		蔵元
		<%= select_tag(:image_maker, options_for_select(Maker.order(:name_yomi).all.collect {|i| [i.name, i.id]}.insert(0, ''), params[:image].nil? ? 0 : params[:image][:maker])) %>
		<br />
		銘柄
		<%= select_tag(:image_production, options_for_select(Product.order(:name_yomi).all.collect {|i| [i.name, i.id]}.insert(0, ''), params[:image].nil? ? 0 : params[:image][:production])) %>
		<br />
		画像タイプ
		<%= select_tag(:image_type, options_for_select(MasterImageType.all.collect {|i| [i.name, i.id]}, params[:image].nil? ? 0 : params[:image][:image_type])) %>
		<br />
		<% end %>
	</td></tr>
	<tr><td>
		<div id='images'></div>
	</td></tr>
	</table>
	<br />

  キーワード<br />
	<% 7.times do |i| %>
	  <%= text_field_tag "keyword[]", (@keywords.nil? or @keywords[i].nil?) ? "" : @keywords[i].keyword %><br />
  <% end %>
  <br />
  お薦めの温度<br />
  <% MasterTemperature.order(:sort).all.each do |m| %>
	  <%= m.name %><%= select_tag "temperature["+m.id.to_s+"]", 
                    options_from_collection_for_select(MasterEvaluation.order(:sort).all, :id, :evaluation, Temperature.get_evaluation(@product.id, m.id).first.nil? ? 1 : Temperature.get_evaluation(@product.id, m.id).first.evaluation) %>
	 <br />
  <% end %>
  <br />
  呑むシーン<br />
  <% MasterFitscene.order(:sort).all.each do |mf| %>
    <%= check_box_tag("fitscene["+mf.id.to_s+"]", mf.id, checked = not(Fitscene.where(:product => params[:id], :fitscene => mf.id).first.nil?)) %><%= mf.name %>
  <% end %><br />
	<br />
  瓶の見た目の印象<br />
  <% MasterEmotion.where(:is_show => true).order(:sort).all.each do |me| %>
	  <%= me.name %><br />
		<% MasterImpression.where(:emotion => me.id).order(:sort).all.each do |mi| %>
      <%= check_box_tag("impression["+mi.id.to_s+"]", mi.id, checked = not(Impression.where(:product => params[:id], :impression => mi.id).first.nil?)) %><%= mi.name %>
    <% end %>
		<hr />
  <% end %>
	<br />
	<%= f.submit "保存" %>
<% end %>
